<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name='format-detection' content='telephone=no' />
<title>人车人</title><link rel="icon" href="/assets/img/titleico.ico" type="image/x-icon">


<link rel="stylesheet" href="/assets/css/common.css" />
<link rel="stylesheet" href="/assets/css/iconfont/iconfont.css" />
<link rel="stylesheet" href="/assets/css/login.css" />

<script src="/assets/js/jquery-3.1.1.min.js"></script>
</head>
<body>
    <header>
        <div id='goBack'>
        	<i class="inlineBlockImg"></i>
        </div>
        <span>登录</span>
        <a href='/login/register'>注册</a>
    </header>
    <section>
        <div id="logo"></div>
        <div>
        	<form id='form'>
	            <ul id="main_form">
	                <li>
	                    <i class="inlineBlockImg inputPhoneLogo"></i>
	                    <input type="text" placeholder="请输入手机号码" id='username'>
	                </li>
	                <li>
	                    <i class="inlineBlockImg inputPassWordLogo"></i>
	                    <input type="password" placeholder="请输入密码" id='password'>
	                </li>
	                <li>
	                    <i class="inlineBlockImg inputCodeLogo"></i>
	                    <input type="text" placeholder="请输入验证码" id='vcode'>
	                    <!--验证码-->
	                    <img alt="" src="" id='yzm' style='width:10rem;padding-bottom:.2rem;'>
	                </li>
	            </ul>
            </form>
        </div>
        <div id="main_footer">
            <i class="blockImg" id='btn'></i>
            <div>
                <a href="/login/register">立即注册</a>
                <a href="/login/forget">忘记密码</a>
            </div>
        </div>
    </section>
    <footer id="footer_text">
        <p>第三方登录</p>
        <div>
            <i class="inlineBlockImg"></i>
            <i class="inlineBlockImg"></i>
        </div>
    </footer>
</body>

<script src="/assets/js/fastclick.min.js"></script>
<script src="/assets/js/xxsg.js"></script>
<script>
	$(function(){
		var form = $("#form"),
			subbtn = $("#btn"),
			isSubmit = true;//控制是否可以点击登录
			
		subbtn.click(function(){
			if(isSubmit){
				isSubmit = false
				submit()
			}
		}); 
			
		getVcode();
		$("#yzm").on("click",function(){
			getVcode();
			
		})
		
		function getVcode(){
			$.ajax({
				type:"post",
				url:"/adminLogin/vcode",
				success:function(data){
					if(data.code!=0){
						#("yzm").src=data.path;
						
					}
				}
			})
		}
		function submit(){
			
			var username = $('#username').val(),
				password = $('#password').val(),
				vcode = $('#vcode').val();

			if(_x.isEmpty(username) || _x.isEmpty(password)){
				console.log(username);
				_x.showTip("请输入手机号或密码");
				isSubmit = true;
				return false;
			}

			if(isNaN(username) || username.indexOf(".") != -1){
				_x.showTip("手机号格式不正确");
				isSubmit = true;
				return false;
			}
			
			if(_x.isEmpty(vcode)){
				_x.showTip("请输入验证码");
				isSubmit = true
				return false;
			}
			
			subbtn.html("<div class='textloading'></div>")
			$.ajax({
				type: "POST",
	            url: "/login/submit",
	            data: {
	            	username:username,
	            	password:password,
	            	vcode:vcode
	            },
	            success: function(data){
	            	if (data.code == 0) {
	               		_x.showTip(data.msg);
					}else{
						if(data.isFirstLogin){
							location.href = "/login/passwordReset";
						}else if(data.repeatLogin){
							alert("该账户已在其他设备登陆，如非本人操作，请尽快修改密码！")
							location.href = "/userCenter";
						}else{
							location.href = data.msg
						}
					}
	            	isSubmit = true
	            },
	            error:function(){
	            	subbtn.html("登录")
	            	isSubmit = true
	            	_x.showTip("网络出错，请稍后重试！")
	            }
			})
		};
		
		$('#username').blur(blurYz);
		$('#password').blur(blurYz);
		$('#vcode').blur(blurYz);
		
		function blurYz(){
			var username = $('#username').val(),
				password = $('#password').val(),
				vcode = $('#vcode').val();
			
			if( !(_x.isEmpty(username)) && !(_x.isEmpty(password)) && !(_x.isEmpty(vcode)) ){
				subbtn.addClass('active')
				console.log(1);
			}else{
				if(subbtn.hasClass('active')){
					subbtn.removeClass('active')
				}
			}

		}
		
		$('#goBack').click(function(e){
			e.preventDefault();
			window.history.go(-1);
		})
		
	})
</script>
</html>